import java.util.Arrays;

/**
 * @Author YuanYuan
 * @Date 2022/5/6
 * @Time 19:40
 */
public class TestDemo {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        int[] copy = new int[arr.length];
        System.arraycopy(arr,0,copy,0,arr.length);
        System.out.println(Arrays.toString(copy));
    }
    public static void main7(String[] args) {
        int[][] array = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][3];
        int[][] array3 = new int[][] {{1,2,3},{4,5,6}};

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("========================");
        for (int [] tmp:array) {
            for (int x:tmp ){
                System.out.print(x+" ");

            }
            System.out.println();
        }
        System.out.println("========================");
        System.out.println(Arrays.deepToString(array));

    }
    public static void main6(String[] args) {
        int[] arr = {1,2,3,4,5};
       // int[] copy = Arrays.copyOf(arr,arr.length*2);
        int[] copy = Arrays.copyOfRange(arr,1,3);
        System.out.println(Arrays.toString(copy));
    }
    public static int findKey(int key,int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == key) {
                return i;
            }
        }
        return -1;
    }
    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        int index = findKey(3,array);
        System.out.println(index);
    }
    public static double avg(int[] array) {
        int sum = 0;
        for(int x:array) {
            sum+=x;
        }
        return sum*1.0/array.length;
    }


    public static void main4(String[] args) {
        int[] arr = {1,2,3,4,7};
        System.out.println(avg(arr));
    }
    public static void main3(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        int[] copy = arr;
        System.out.println(Arrays.toString(copy));
    }
    public static void main2 (String[] args) {
        int[] arr = {1,2,3,4,5};
        int[] copy = arr.clone();
        System.out.println(Arrays.toString(copy));
    }
    public static void main1(String[] args) {
        int[] arr = {1,2,3,4,5};
        //int[] copy = Arrays.copyOf(arr,arr.length);
        int[] copy = Arrays.copyOf(arr,3);
        System.out.println(Arrays.toString(copy));
        int[] copy1 = arr.clone();
        System.out.println(Arrays.toString(copy1));
    }
}
